//
//  XKMineAssetsCell.m
//  XKJY
//
//  Created by xuyaguang on 2017/1/12.
//  Copyright © 2017年 xiaokang100. All rights reserved.
//

#import "XKMineAssetsCell.h"
#import "XKMineAssetsCollectionCell.h"

static NSString *XKMineAssetsCollcetionCellID = @"XKMineAssetsCollcetionCellReuseIdentifier";

@interface XKMineAssetsCell () <UICollectionViewDataSource, UICollectionViewDelegate>

@property (nonatomic, strong) UICollectionView *collectionView;

@end
@implementation XKMineAssetsCell

#pragma mark - 自定义cell重写构造方法
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self configArguments];
        [self createSubviews];
        [self addConstraints];
    }
    return self;
}

#pragma mark - 设置自身
- (void)configArguments {
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.backgroundColor = kBaseGrayColor;
}

#pragma mark - 创建控件
- (void)createSubviews {
    
}
#pragma mark - 添加约束
- (void)addConstraints {

    [self.contentView addSubview:self.collectionView];
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView).offset(5*Scale_H);
        make.left.mas_equalTo(self.contentView);
        make.height.mas_equalTo(Main_Width/3);
        make.width.mas_equalTo(Main_Width);
        make.bottom.mas_equalTo(self.contentView).offset(-5*Scale_H).priorityHigh();
    }];
}

- (UICollectionView *)collectionView {
    if (!_collectionView) {
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.scrollDirection = UICollectionViewScrollDirectionVertical;
        layout.minimumLineSpacing = 2;
        layout.minimumInteritemSpacing = 1;
        layout.itemSize = CGSizeMake((Main_Width-2*Scale_W)/2, (Main_Width-2*Scale_W)/6);
        layout.headerReferenceSize = CGSizeZero;
        layout.footerReferenceSize = CGSizeZero;
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
        _collectionView.backgroundColor = kBaseGrayColor;
        _collectionView.dataSource = self;
        _collectionView.delegate = self;
        _collectionView.scrollEnabled = NO;
        
        [_collectionView registerClass:[XKMineAssetsCollectionCell class] forCellWithReuseIdentifier:XKMineAssetsCollcetionCellID];
    }
    return _collectionView;
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 4;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    XKMineAssetsCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:XKMineAssetsCollcetionCellID forIndexPath:indexPath];
    cell.titleString = @[@"我的种子",@"人民币资产", @"种子收入", @"我的通宝"][indexPath.item];
    cell.textString = self.dataArray[indexPath.item];
    
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    [collectionView deselectItemAtIndexPath:indexPath animated:YES];
    
}

- (void)setDataArray:(NSArray *)dataArray {
    _dataArray = dataArray;
    [self.collectionView reloadData];
}




@end
